__doc__ =   """ Module with various utility functions.
            """

def find_duplicate_chains(model):
    """ Finds the number of identical residues in chain pairs.
        @type  model: entity
        @param model: the model entity
        @return: a square dictionary-array of the pairwise number of
            identical residues eg.:
                {('A',) : {('B',):62,('C',):12}
                 ('B',) : {('A',):62,('C',):33}
                 ('C',) : {('A',):12,('B',):33}}
    """
    chains = model.get_children()
    result_chart = defaultdict(dict)
    for chain_1, chain_2 in combinate(chains, 2):
        common =  set(chain_1.keys())
        common.intersection_update(chain_2.keys())
        score = len(common)
        result_chart[chain_1.id][chain_2.id] = score
        result_chart[chain_2.id][chain_1.id] = score
    return result_chart

#END